

class StockViewService:


def get_stock_table_info(self, sortBy: str) -> TableDataDto:
        """
        根据传入的参数查询股票数据，并返回格式化的报表数据。
        :param params: 查询参数字典
        :return: TableDataDto 对象
        """
        AntLogger.info(f"getStockTableInfo 传入查询的对象信息{sortBy}")

        stockService = StockMainService()

        # 获取排序后的股票数据
        stock_list = stockService.listSelfStock(sort_by=sortBy)

        # 格式化股票数据为表格形式
        table_data = []
        for stock in stock_list:
            # 格式化股票数据
            stock_code = stock.stock_code
            stock_name = stock.stock_name
            stock_current_price = (
                f"{stock.monitor_current_price:.2f}"
                if stock.monitor_current_price
                else "N/A"
            )
            monitor_income_ratio = (
                f"{stock.monitor_income_ratio:.2f}%"
                if stock.monitor_income_ratio is not None
                else "N/A"
            )
            stock_risk_level = stockService.get_risk_level_description(
                stock.stock_risk_level
            )

            table_data.append(
                [
                    stock_code,
                    stock_name,
                    stock_current_price,
                    monitor_income_ratio,
                    stock_risk_level,
                ]
            )

        # 返回表格数据
        return TableDataDto(
            table_header=[
                "股票代码",
                "股票名称",
                "股票当前价",
                "当前盈亏比例",
                "当前风险等级",
            ],
            table_data=table_data,
            table_item_fun=[{"查看详情": self.showTableDatail}],
        )
